

package com.xyy.ec.pop.erp.hx.po.pop;


import com.xyy.ec.pop.erp.hx.enums.ApiResultCodeEum;
import com.xyy.ec.pop.erp.hx.enums.ApiResultExceptionTypeEum;

import java.io.Serializable;

public class ApiRPCResult<T> implements Serializable {
    private static final long serialVersionUID = 8217111902267503831L;
    private int code;
    private int subcode;
    private int exType;
    private String appName;
    private String msg;
    private String errMsg;
    private T data;

    public ApiRPCResult() {
    }

    public ApiRPCResult(int code, int subcode, int exType, String msg, String errMsg, T data) {
        this.code = code;
        this.subcode = subcode;
        this.exType = exType;
        this.msg = msg;
        this.errMsg = errMsg;
        this.data = data;
    }

    public ApiRPCResult(int code, String appName, String msg, String errMsg, T data) {
        this.code = code;
        this.appName = appName;
        this.msg = msg;
        this.errMsg = errMsg;
        this.data = data;
    }

    public static ApiRPCResult buildSuccess(Object data) {
        return (new ApiRPCResult()).setCode(ApiResultCodeEum.SUCCESS.getCode()).setData(data);
    }

    public static ApiRPCResult buildFail(ApiResultCodeEum apiResultCodeEum, ApiResultExceptionTypeEum apiResultExceptionTypeEum, String errorMsg) {
        return (new ApiRPCResult()).setCode(apiResultCodeEum.getCode()).setMsg(apiResultCodeEum.getMsg()).setData((Object) null).setErrMsg(errorMsg).setExType(apiResultExceptionTypeEum.getCode());
    }

    public static ApiRPCResult buildFail(ApiResultCodeEum apiResultCodeEum, ApiResultExceptionTypeEum apiResultExceptionTypeEum, Object data, String errorMsg) {
        return (new ApiRPCResult()).setCode(apiResultCodeEum.getCode()).setMsg(apiResultCodeEum.getMsg()).setData(data).setErrMsg(errorMsg).setExType(apiResultExceptionTypeEum.getCode());
    }

    public static ApiRPCResult buildFailNoneCheck(ApiResultCodeEum apiResultCodeEum, String errorMsg) {
        return (new ApiRPCResult()).setCode(apiResultCodeEum.getCode()).setMsg(apiResultCodeEum.getMsg()).setData((Object) null).setErrMsg(errorMsg).setExType(ApiResultExceptionTypeEum.UN_NEED_CHECK.getCode());
    }

    public static ApiRPCResult buildFailCheck(ApiResultCodeEum apiResultCodeEum, String errorMsg) {
        return (new ApiRPCResult()).setCode(apiResultCodeEum.getCode()).setMsg(apiResultCodeEum.getMsg()).setData((Object) null).setErrMsg(errorMsg).setExType(ApiResultExceptionTypeEum.NEED_CHECK.getCode());
    }

    public static ApiRPCResult buildFailCheck(ApiResultCodeEum apiResultCodeEum, String errorMsg, Object data) {
        return (new ApiRPCResult()).setCode(apiResultCodeEum.getCode()).setMsg(apiResultCodeEum.getMsg()).setData(data).setErrMsg(errorMsg).setExType(ApiResultExceptionTypeEum.NEED_CHECK.getCode());
    }

    public static ApiRPCResult buildFailCheck(int code, String errorMsg, Object data) {
        return (new ApiRPCResult()).setCode(code).setMsg(errorMsg).setData(data).setErrMsg(errorMsg).setExType(ApiResultExceptionTypeEum.NEED_CHECK.getCode());
    }

    public static ApiRPCResult buildFailWithSubCode(ApiResultCodeEum apiResultCodeEum, ApiResultExceptionTypeEum apiResultExceptionTypeEum, Object data, String errorMsg, int subcode) {
        return (new ApiRPCResult()).setCode(apiResultCodeEum.getCode()).setMsg(apiResultCodeEum.getMsg()).setData(data).setErrMsg(errorMsg).setExType(apiResultExceptionTypeEum.getCode()).setSubcode(subcode);
    }

    public boolean isSuccess() {
        return this.code == ApiResultCodeEum.SUCCESS.getCode();
    }

    public boolean isFail() {
        return this.code != ApiResultCodeEum.SUCCESS.getCode();
    }

    public static long getSerialVersionUID() {
        return 8217111902267503831L;
    }

    public int getCode() {
        return this.code;
    }

    public ApiRPCResult setCode(int code) {
        this.code = code;
        return this;
    }

    public int getSubcode() {
        return this.subcode;
    }

    public ApiRPCResult setSubcode(int subcode) {
        this.subcode = subcode;
        return this;
    }

    public int getExType() {
        return this.exType;
    }

    public ApiRPCResult setExType(int exType) {
        this.exType = exType;
        return this;
    }

    public String getMsg() {
        return this.msg;
    }

    public ApiRPCResult setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public String getErrMsg() {
        return this.errMsg;
    }

    public ApiRPCResult setErrMsg(String errMsg) {
        this.errMsg = errMsg;
        return this;
    }

    public T getData() {
        return this.data;
    }

    public ApiRPCResult setData(T data) {
        this.data = data;
        return this;
    }

    public String getAppName() {
        return this.appName;
    }

    public void setAppName(String appName) {
        this.appName = appName;
    }
}
